///*
// *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
// *
// *  Redistribution and use in source and binary forms, with or without
// *  modification, are permitted provided that the following conditions are met:
// *
// *  Redistributions of source code must retain the above copyright notice,
// *  this list of conditions and the following disclaimer.
// *  Redistributions in binary form must reproduce the above copyright
// *  notice, this list of conditions and the following disclaimer in the
// *  documentation and/or other materials provided with the distribution.
// *  Neither the name of the dreamlu.net developer nor the names of its
// *  contributors may be used to endorse or promote products derived from
// *  this software without specific prior written permission.
// *  Author: Chill 庄骞 (smallchill@163.com)
// */
//package com.plian.system.controller.fr.vehicle;
//
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.fasterxml.jackson.core.type.TypeReference;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.plian.Tools.DateUtil;
//import com.plian.Tools.FileTools;
//import com.plian.Tools.Func;
//import com.plian.Tools.StringPool;
//import com.plian.Tools.base.BaseController;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.common.status.CustomCode;
//import com.plian.system.config.Resubmit;
//import com.plian.system.dto.fr.vehicle.PurchaseSummaryDTO;
//import com.plian.system.dto.fr.vehicle.VehicleInfoDTO;
//import com.plian.system.entity.fr.vehicle.VehicleInfo;
//import com.plian.system.entity.fr.vehicle.VehicleScrap;
//import com.plian.system.entity.fr.vehicle.VehicleUpdate;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.model.ObjResult;
//import com.plian.system.model.R;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.search.TokenSearch;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.service.fr.vehicle.IVehicleInfoService;
//import com.plian.system.service.fr.vehicle.IVehicleScrapService;
//import com.plian.system.service.fr.vehicle.IVehicleUpdateService;
//import com.plian.system.vo.fr.vehicle.VehicleUpdateVO;
//import com.plian.system.vo.report.ReportReturnVO;
//import com.plian.system.wrapper.fr.veihicle.VehicleInfoWrapper;
//import com.plian.system.wrapper.fr.veihicle.VehicleScrapWrapper;
//import com.plian.system.wrapper.fr.veihicle.VehicleUpdateWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.core.io.FileSystemResource;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import javax.validation.Valid;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Optional;
//
///**
// * 车辆购置更新管理 控制器
// *
// * @author jianglei
// * @since 2019-09-26
// */
//
//@Slf4j
//@RestController
//@RequestMapping("api/vehicleupdate")
//@AllArgsConstructor
//public class VehicleUpdateController extends BaseController {
//
//	private IVehicleUpdateService vehicleUpdateService;
//
//	private IVehicleInfoService vehicleInfoService;
//
//	private IVehicleScrapService vehicleScrapService;
//
//	private VehicleInfoWrapper vehicleInfoWrapper;
//
//	private VehicleScrapWrapper vehicleScrapWrapper;
//
//	private VehicleUpdateWrapper vehicleUpdateWrapper;
//
//
//	/**
//	 * 详情
//	 */
//	@PostMapping("/detail")
//	public ObjResult detail(@Valid @RequestBody VehicleUpdate vehicleUpdate) {
//		ObjResult objResult;
//
//		try{
//			VehicleUpdate detail = vehicleUpdateService.getOne(Condition.getQueryWrapper(vehicleUpdate));
//
//			objResult = new ObjResult(CommonCode.SUCCESS);
//			if (Optional.ofNullable(detail).isPresent()){
//				PageData pd = new PageData();
//				VehicleInfo vehicleInfo = new VehicleInfo();
//				vehicleInfo.setVehicleUpdateId(detail.getId());
//				pd.put("vehicleInfos", vehicleInfoWrapper.entityToVO(vehicleInfoService.list(Condition.getQueryWrapper(vehicleInfo))));
//
//				VehicleScrap vehicleScrap = new VehicleScrap();
//				vehicleScrap.setVehicleUpdateId(detail.getId());
//				pd.put("vehicleScraps", vehicleScrapWrapper.entityToVO(vehicleScrapService.list(Condition.getQueryWrapper(vehicleScrap))));
//
//				VehicleUpdateVO vehicleUpdateVO = vehicleUpdateWrapper.entityToVO(detail);
//				ObjectMapper mapper = new ObjectMapper();
//				String json = JSON.toJSONStringWithDateFormat(vehicleUpdateVO, DateUtil.PATTERN_DATETIME);
//				pd.putAll(mapper.readValue(json, new TypeReference<HashMap<String,String>>(){}));
//
//				objResult.setPageData(pd);
//			}
//
//		}catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//			objResult = new ObjResult(CommonCode.ERROR);
//			return objResult;
//		}
//
//		return objResult;
//	}
//
//	/**
//	 * 分页 车辆购置更新管理
//	 */
//	@PostMapping("/list")
//	public ListResult<VehicleUpdateVO> list(@Valid @RequestBody Query query) {
//		if (query.getAscs()==null&&query.getDescs()==null){
//			query.setDescs("create_time");
//		}
//
//		List<SearchEntity> entityList = query.getSearch();
//		QueryWrapper<VehicleUpdate> queryWrapper = SearchParamEntiy.getQueryWrapper(
//				Condition.getQueryWrapper(new VehicleUpdate()), entityList
//		);
//		TokenSearch<VehicleUpdate> tokenSearch = new TokenSearch<>();
//		tokenSearch.addTokenQuery(queryWrapper, query);
//		IPage<VehicleUpdate> pages = vehicleUpdateService.page(Condition.getPage(query), queryWrapper);
//
//		List<VehicleUpdateVO> vehicleUpdateVOS = vehicleUpdateWrapper.entityToVO(pages.getRecords());
//		ListResult<VehicleUpdateVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//		listResult.setList(vehicleUpdateVOS);
//		listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//		return listResult;
//	}
//
//
//	/**
//	 * 新增或修改 车辆购置更新管理
//	 */
//	@PostMapping("/submit")
//	@Resubmit(delaySeconds = 0)
//	public R submit(@Valid @RequestBody VehicleUpdate vehicleUpdate) {
//		if (!(Optional.ofNullable(vehicleUpdate).isPresent() && Optional.ofNullable(vehicleUpdate.getStatus()).isPresent()
//		&& vehicleUpdate.getStatus() == -1)){
//			String message = vehicleUpdateService.checkSubmit(vehicleUpdate);
//			if (Optional.ofNullable(message).isPresent()){
//				return new R(CustomCode.builder().message(message).code(1999).success(false).build());
//			}
//
//			if(!(vehicleUpdate.getVehicleInfos()!=null && vehicleUpdate.getVehicleInfos().size()>0)){
//				return new R(CustomCode.builder().message("车辆信息未填").code(1999).success(false).build());
//			}
//		}
//
//		return vehicleUpdateService.submit(vehicleUpdate, 1)
//				? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//	/**
//	 * 删除 车辆购置更新管理
//	 */
//	@PostMapping("/remove")
//	public R remove(@RequestBody PageData pd) {
//		List<String> ids = (List<String>)pd.get("ids");
//		return vehicleUpdateService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA)))
//				? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//	/**
//	 * 变更 车辆购置更新管理
//	 */
//	@PostMapping("/change")
//	public ObjResult change(@Valid @RequestBody VehicleUpdate vehicleUpdate) {
//		if (!vehicleUpdateService.checkCancel(vehicleUpdate.getId(),vehicleUpdate.getVehicleInfos())){
//			ObjResult objResult;
//			objResult = new ObjResult(CommonCode.FAIL);
//			PageData pd = new PageData();
//			pd.put("message", "无法变更");
//			return objResult;
//		}
//		return vehicleUpdateService.change(vehicleUpdate);
//	}
//
//	/**
//	 * 宁波市属国有企业业务经营保障用车购置汇总表
//	 */
//	@PostMapping("/purchaseSummary")
//	public ObjResult purchaseSummary(@Valid @RequestBody(required = false) PurchaseSummaryDTO purchaseSummaryDTO) {
//		ObjResult objResult;
//		try {
//			ReportReturnVO reportReturnVO = vehicleUpdateService.purchaseSummary(purchaseSummaryDTO);
//			objResult = new ObjResult(CommonCode.SUCCESS);
//			if (Optional.ofNullable(reportReturnVO).isPresent()){
//				PageData pd = new PageData();
//				pd.put("grids", reportReturnVO.getGrids());
//				objResult.setPageData(pd);
//			}
//
//		}catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//			objResult = new ObjResult(CommonCode.ERROR);
//			return objResult;
//		}
//
//		return objResult;
//	}
//
//
//	/**
//	 * 宁波市属国有企业自有业务经营保障用车存量情况统计表
//	 */
//	@PostMapping("/stockStatistics")
//	public ObjResult stockStatistics(@Valid @RequestBody(required = false) VehicleInfoDTO vehicleInfoDTO) {
//		ObjResult objResult;
//		try {
//			ReportReturnVO reportReturnVO = vehicleInfoService.stockStatistics(vehicleInfoDTO);
//			objResult = new ObjResult(CommonCode.SUCCESS);
//			if (Optional.ofNullable(reportReturnVO).isPresent()){
//				PageData pd = new PageData();
//				pd.put("grids", reportReturnVO.getGrids());
//				objResult.setPageData(pd);
//			}
//		}catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//			objResult = new ObjResult(CommonCode.ERROR);
//			return objResult;
//		}
//
//		return objResult;
//	}
//
//	/**
//	 * 打印
//	 */
//	@GetMapping("/buildpdf/{id}")
//	public ResponseEntity<FileSystemResource> buildPdf(@PathVariable Long id) {
//		return FileTools.exportPdf(vehicleUpdateService.buildpdf(id));
//	}
//}
